﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Fyp.Models;
using WebMatrix.WebData;
using System.Web.Security;

namespace Fyp.Controllers
{
    public class NotificationController : Controller
    {
        //
        // GET: /Notification/

        public ActionResult Notification()
        {

            var db = new FYPEntities5();

            try
            {
                var idKey = (from i in db.MeetingSchedulers
                             orderby i.MeetingId descending
                             select i.MeetingId).First();

                var mTitle = from m in db.MeetingSchedulers
                             select m.MeetingTitle;

                int userId = WebSecurity.CurrentUserId;
                var userName = WebSecurity.CurrentUserName;

                var getGid = (from g in db.Students
                              where userName == g.Std_Email
                              select g.GId).FirstOrDefault();

                var list = from n in db.Notifications
                           where getGid == n.GId
                           select n;

                if (WebSecurity.IsAuthenticated && Roles.IsUserInRole("Advisor"))
                {
                    var getAdvisor = from no in db.Notifications
                                     where userId == no.UserId
                                     select no;

                    if (getAdvisor != null)
                    {
                        ViewData["list"] = getAdvisor.ToList();
                    }
                    //var id = from m in db.MeetingSchedulers
                    //         where (m.CommentText != "" || m.CommentText== null) && m.MeetingType == "Proposed"
                    //         select m.MeetingId;
                    //var result = from r in db.Notifications
                    //             where userId== r.UserId 
                }
                else
                {
                    ViewData["list"] = list.ToList();
                }

            }
            catch (Exception e)
            {
                Console.WriteLine(e.InnerException);
            }

            return View("Notification");
        }

    }

}
